﻿using Microsoft.EntityFrameworkCore.Migrations;

namespace Xc.WaterMeters.ServerHosts.Migrations
{
    public partial class M3 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_AlarmInfoHistorys_DeviceInfos_DeviceInfoId",
                table: "AlarmInfoHistorys");

            migrationBuilder.DropForeignKey(
                name: "FK_AlarmInfos_DeviceInfos_DeviceInfoId",
                table: "AlarmInfos");

            migrationBuilder.DropForeignKey(
                name: "FK_CommandInfos_DeviceInfos_DeviceInfoId",
                table: "CommandInfos");

            migrationBuilder.DropForeignKey(
                name: "FK_PropertyInfoHistorys_DeviceInfos_DeviceInfoId",
                table: "PropertyInfoHistorys");

            migrationBuilder.DropForeignKey(
                name: "FK_PropertyInfos_DeviceInfos_DeviceInfoId",
                table: "PropertyInfos");

            migrationBuilder.DropColumn(
                name: "DeviceId",
                table: "DeviceInfos");

            migrationBuilder.AlterColumn<string>(
                name: "DeviceInfoId",
                table: "PropertyInfos",
                type: "TEXT",
                nullable: true,
                oldClrType: typeof(ulong),
                oldType: "INTEGER");

            migrationBuilder.AlterColumn<string>(
                name: "DeviceInfoId",
                table: "PropertyInfoHistorys",
                type: "TEXT",
                nullable: true,
                oldClrType: typeof(ulong),
                oldType: "INTEGER");

            migrationBuilder.AlterColumn<string>(
                name: "Id",
                table: "DeviceInfos",
                type: "TEXT",
                nullable: false,
                oldClrType: typeof(ulong),
                oldType: "INTEGER")
                .OldAnnotation("Sqlite:Autoincrement", true);

            migrationBuilder.AlterColumn<string>(
                name: "DeviceInfoId",
                table: "CommandInfos",
                type: "TEXT",
                nullable: true,
                oldClrType: typeof(ulong),
                oldType: "INTEGER");

            migrationBuilder.AlterColumn<string>(
                name: "CommandType",
                table: "CommandInfos",
                type: "TEXT",
                nullable: true,
                oldClrType: typeof(long),
                oldType: "INTEGER");

            migrationBuilder.AlterColumn<string>(
                name: "DeviceInfoId",
                table: "AlarmInfos",
                type: "TEXT",
                nullable: true,
                oldClrType: typeof(ulong),
                oldType: "INTEGER");

            migrationBuilder.AlterColumn<string>(
                name: "DeviceInfoId",
                table: "AlarmInfoHistorys",
                type: "TEXT",
                nullable: true,
                oldClrType: typeof(ulong),
                oldType: "INTEGER");

            migrationBuilder.AddForeignKey(
                name: "FK_AlarmInfoHistorys_DeviceInfos_DeviceInfoId",
                table: "AlarmInfoHistorys",
                column: "DeviceInfoId",
                principalTable: "DeviceInfos",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_AlarmInfos_DeviceInfos_DeviceInfoId",
                table: "AlarmInfos",
                column: "DeviceInfoId",
                principalTable: "DeviceInfos",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_CommandInfos_DeviceInfos_DeviceInfoId",
                table: "CommandInfos",
                column: "DeviceInfoId",
                principalTable: "DeviceInfos",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PropertyInfoHistorys_DeviceInfos_DeviceInfoId",
                table: "PropertyInfoHistorys",
                column: "DeviceInfoId",
                principalTable: "DeviceInfos",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_PropertyInfos_DeviceInfos_DeviceInfoId",
                table: "PropertyInfos",
                column: "DeviceInfoId",
                principalTable: "DeviceInfos",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_AlarmInfoHistorys_DeviceInfos_DeviceInfoId",
                table: "AlarmInfoHistorys");

            migrationBuilder.DropForeignKey(
                name: "FK_AlarmInfos_DeviceInfos_DeviceInfoId",
                table: "AlarmInfos");

            migrationBuilder.DropForeignKey(
                name: "FK_CommandInfos_DeviceInfos_DeviceInfoId",
                table: "CommandInfos");

            migrationBuilder.DropForeignKey(
                name: "FK_PropertyInfoHistorys_DeviceInfos_DeviceInfoId",
                table: "PropertyInfoHistorys");

            migrationBuilder.DropForeignKey(
                name: "FK_PropertyInfos_DeviceInfos_DeviceInfoId",
                table: "PropertyInfos");

            migrationBuilder.AlterColumn<ulong>(
                name: "DeviceInfoId",
                table: "PropertyInfos",
                type: "INTEGER",
                nullable: false,
                defaultValue: 0ul,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldNullable: true);

            migrationBuilder.AlterColumn<ulong>(
                name: "DeviceInfoId",
                table: "PropertyInfoHistorys",
                type: "INTEGER",
                nullable: false,
                defaultValue: 0ul,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldNullable: true);

            migrationBuilder.AlterColumn<ulong>(
                name: "Id",
                table: "DeviceInfos",
                type: "INTEGER",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "TEXT")
                .Annotation("Sqlite:Autoincrement", true);

            migrationBuilder.AddColumn<string>(
                name: "DeviceId",
                table: "DeviceInfos",
                type: "TEXT",
                nullable: true);

            migrationBuilder.AlterColumn<ulong>(
                name: "DeviceInfoId",
                table: "CommandInfos",
                type: "INTEGER",
                nullable: false,
                defaultValue: 0ul,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldNullable: true);

            migrationBuilder.AlterColumn<long>(
                name: "CommandType",
                table: "CommandInfos",
                type: "INTEGER",
                nullable: false,
                defaultValue: 0L,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldNullable: true);

            migrationBuilder.AlterColumn<ulong>(
                name: "DeviceInfoId",
                table: "AlarmInfos",
                type: "INTEGER",
                nullable: false,
                defaultValue: 0ul,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldNullable: true);

            migrationBuilder.AlterColumn<ulong>(
                name: "DeviceInfoId",
                table: "AlarmInfoHistorys",
                type: "INTEGER",
                nullable: false,
                defaultValue: 0ul,
                oldClrType: typeof(string),
                oldType: "TEXT",
                oldNullable: true);

            migrationBuilder.AddForeignKey(
                name: "FK_AlarmInfoHistorys_DeviceInfos_DeviceInfoId",
                table: "AlarmInfoHistorys",
                column: "DeviceInfoId",
                principalTable: "DeviceInfos",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_AlarmInfos_DeviceInfos_DeviceInfoId",
                table: "AlarmInfos",
                column: "DeviceInfoId",
                principalTable: "DeviceInfos",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_CommandInfos_DeviceInfos_DeviceInfoId",
                table: "CommandInfos",
                column: "DeviceInfoId",
                principalTable: "DeviceInfos",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_PropertyInfoHistorys_DeviceInfos_DeviceInfoId",
                table: "PropertyInfoHistorys",
                column: "DeviceInfoId",
                principalTable: "DeviceInfos",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_PropertyInfos_DeviceInfos_DeviceInfoId",
                table: "PropertyInfos",
                column: "DeviceInfoId",
                principalTable: "DeviceInfos",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
